package com.woniu40.petai_manager.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu40.petai_manager.entity.Dynamic;
import com.woniu40.petai_manager.mapper.DynamicMapper;
import com.woniu40.petai_manager.vo.DynamicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DynamicService {
    @Autowired
    DynamicMapper dynamicMapper;

    @Transactional
    public int priority(Integer dynamicId){
        dynamicMapper.dancelPriority();
        int i = dynamicMapper.updatePriority(dynamicId);
        return i;
    }

    public PageInfo<DynamicVo> findAll(Integer pageNum,Integer pageSize,String name){
        PageHelper.startPage(pageNum,pageSize);
        List<DynamicVo> dynamics = dynamicMapper.selectAll(name);
        PageInfo<DynamicVo> dynamicPageInfo = new PageInfo<>(dynamics);
        return dynamicPageInfo;
    }

    public int delete(Integer id){
        int i = dynamicMapper.deleteByPrimaryKey(id);
        return i;
    }

}
